﻿<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>

<%
	Message msg = new Message();
	
	Connection connection = null;
	CallableStatement statement = null;
	ResultSet rs = null;
	try {
			String 	mac        = "";   
			String 	patid      = input.getDesc("patid");  
			String 	ksdm       = input.getDesc("ksdm"); 
			String 	pbmxxh     = input.getDesc("pbmxxh");   
			String 	yyxh       = input.getDesc("yyxh");  
			String sjh = "";
			String state = "";
			String message = "";
			connection = getConn();
			statement = connection.prepareCall("{call 预约挂号登记('"+mac+"', 1, 0, 9, 0, 0, "+patid+", '00', '"+ksdm+"', '', '"+ksdm+"', 'SJH', 1, "+yyxh+", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'',0,'',0, 0,'','','','',0,'1','','','',@yyrq='',@zqdm='',@jmjsbz=0,@inghzdxh=0,@zymzxh = 0, @pbmxxh="+pbmxxh+", @xmldxx='',@ghfdm='',@kmdm='',@yhdm='',@zbdm='')}");
			rs = statement.executeQuery();
			
			while(rs.next()){
				// 获取列数,根据返回的列数获取不同参数
				ResultSetMetaData rsmd = rs.getMetaData();
				int columnCount = rsmd.getColumnCount();
				state=rs.getString(1);
				if(columnCount==2) {
					message=rs.getString(2);
				}
				if("F".equalsIgnoreCase(state)) {
					msg.put("errcode",FAILURE);
					msg.put("errmsg",message);
				}
			}
			statement = connection.prepareCall("{call 预约挂号登记('"+mac+"', 2, 0, 9, 0, 0, "+patid+", '00', '"+ksdm+"', '', '"+ksdm+"', 'SJH', 1, "+yyxh+", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'',0,'',0, 0,'','','','',0,'1','','','',@yyrq='',@zqdm='',@jmjsbz=0,@inghzdxh=0,@zymzxh = 0, @pbmxxh="+pbmxxh+", @xmldxx='',@ghfdm='',@kmdm='',@yhdm='',@zbdm='')}");
			rs = statement.executeQuery();
			while(rs.next()){
				// 获取列数,根据返回的列数获取不同参数
				ResultSetMetaData rsmd = rs.getMetaData();
				int columnCount = rsmd.getColumnCount();
				state=rs.getString(1);
				if(columnCount==2) {
					message=rs.getString(2);
				}
				if("F".equalsIgnoreCase(state)) {
					msg.put("errcode",FAILURE);
					msg.put("errmsg",message);
				}
			}
			statement = connection.prepareCall("{call 预约挂号登记('"+mac+"', 3, 0, 9, 0, 0, "+patid+", '00', '"+ksdm+"', '', '"+ksdm+"', 'SJH', 1, "+yyxh+", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'',0,'',0, 0,'','','','',0,'1','','','',@yyrq='',@zqdm='',@jmjsbz=0,@inghzdxh=0,@zymzxh = 0, @pbmxxh="+pbmxxh+", @xmldxx='',@ghfdm='',@kmdm='',@yhdm='',@zbdm='')}");
			rs = statement.executeQuery();
			while(rs.next()){
				// 获取列数,根据返回的列数获取不同参数
				ResultSetMetaData rsmd = rs.getMetaData();
				int columnCount = rsmd.getColumnCount();
				state=rs.getString(1);
				if(columnCount==2) {
					message=rs.getString(2);
				}
				if("F".equalsIgnoreCase(state)) {
					msg.put("errcode",FAILURE);
					msg.put("errmsg",message);
				} else if("T".equalsIgnoreCase(state)) {
					sjh=rs.getString(3);
					if(sjh!=null) {
						sjh=sjh.trim();
					}
				}
			}
			statement = connection.prepareCall("{call 预约挂号收费('"+mac+"',3,2,9,0,0,"+patid+",'00','"+ksdm+"','','"+ksdm+"','"+sjh+"',1,"+yyxh+")}");
			rs = statement.executeQuery();
			while(rs.next()){
			
				// 获取列数,根据返回的列数获取不同参数
				ResultSetMetaData rsmd = rs.getMetaData();
				int columnCount = rsmd.getColumnCount();
				state=rs.getString(1);
				if(columnCount==2) {
					message=rs.getString(2);
				}
			
			if("F".equalsIgnoreCase(state)) {
					msg.put("errcode",FAILURE);
					msg.put("errmsg",message);
				} else if("T".equalsIgnoreCase(state)) {
					sjh=rs.getString(3);
					if(sjh!=null) {
						sjh=sjh.trim();
					}
				}
			}
			
		} catch (Exception e){
	   	msg.put("errcode",FAILURE);
    } finally {
			try {
					if (rs != null)
						rs.close(); 
					if (statement != null)
						statement.close(); 
					if (connection != null)
						connection.close(); 
				} catch (Exception e) {
					rs = null;
					statement = null;
					connection = null;
					e.printStackTrace();
				}
		}
		out.println(msg);
%>